package demo08;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-10
 * Time: 21:10
 */
class Tick {
    int count = 20;
    synchronized public  void Counter (){
        count--;
    }
}
public class Test03 {
    public static void main(String[] args) {
        Tick ttt = new Tick();
        Thread t1 = new Thread( new Runnable() {
            @Override
            public void run() {
                while (ttt.count != 0) {
                    ttt.Counter();
                }
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (ttt.count != 0) {
                    ttt.Counter();
                }
            }
        });

        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (ttt.count != 0) {
                    ttt.Counter();
                }
            }
        });
        t1.start();
        t2.start();
        t3.start();
        try {
            t1.join();
            t2.join();
            t3.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(ttt.count);
    }


}
